package cn.yuanqiao.web.controller.archive.api;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.api.domain.ReceiveRecord;
import cn.yuanqiao.archive.api.service.IReceiveRecordService;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.common.utils.SecurityUtils;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 接收记录Controller
 *
 * @author xy
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/archive/receiveRecord")
public class ReceiveRecordController extends BaseController
{
    @Autowired
    private IReceiveRecordService receiveRecordService;

    /**
     * 查询接收记录列表
     */

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('archive:receiveLog:list')")
    public TableDataInfo list(ReceiveRecord receiveRecord)
    {
        receiveRecord.setTenantCode(SecurityUtils.getTenantCode());
        startPage();
        List<ReceiveRecord> list = receiveRecordService.selectReceiveRecordList(receiveRecord);
        return getDataTable(list);
    }

    /**
     * 导出接收记录列表
     */
    @Log(title = "接收记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiveRecord receiveRecord)
    {
        List<ReceiveRecord> list = receiveRecordService.selectReceiveRecordList(receiveRecord);
        ExcelUtil<ReceiveRecord> util = new ExcelUtil<ReceiveRecord>(ReceiveRecord.class);
        util.exportExcel(response, list, "接收记录数据");
    }

    /**
     * 获取接收记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(receiveRecordService.selectReceiveRecordById(id));
    }

    /**
     * 新增接收记录
     */
    @Log(title = "接收记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiveRecord receiveRecord)
    {
        return toAjax(receiveRecordService.insertReceiveRecord(receiveRecord));
    }

    /**
     * 修改接收记录
     */
    @Log(title = "接收记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiveRecord receiveRecord)
    {
        return toAjax(receiveRecordService.updateReceiveRecord(receiveRecord));
    }

    /**
     * 删除接收记录
     */
    @Log(title = "接收记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiveRecordService.deleteReceiveRecordByIds(ids));
    }
}
